package com.bailian.spring.ioc.complex_di.config;

import com.bailian.spring.ioc.complex_di.bean.Cat;
import com.bailian.spring.ioc.complex_di.bean.Person;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author gaoxu
 * date: Created on 2021/10/29 下午3:17
 */
@Configuration
@ComponentScan("com.bailian.spring.ioc.complex_di.bean")
public class ComplexDiConfig {

    @Bean
    public Cat cat(@Qualifier("slave") Person person) {
        Cat cat = new Cat();
        cat.setName("小花猫");
        cat.setMaster(person);
        return cat;
    }

    @Bean
    @Primary
    public Person master() {
        Person person = new Person();
        person.setName("李四");
        return person;
    }
}

